package com.stock.controller;

import com.stock.domain.vo.response.PageResponse;
import com.stock.domain.vo.response.Response;
import com.stock.service.StockService;
import com.stock.pojo.domain.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

//TODO：股票业务相关接口
@Api(value = "/api/quot", tags = {"TODO：股票业务相关接口"})
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;

    //查询A股大盘实时信息
    @ApiOperation(value = "查询A股大盘实时信息", notes = "查询A股大盘实时信息", httpMethod = "GET")
    @GetMapping("/index/all")
    public Response<List<InnerMarketDomain>> getInnerMarketAll() {
        return stockService.getInnerMarketAll();
    }

    //获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据
    @ApiOperation(value = "获取沪深两市板块最新数据", notes = "获取沪深两市板块最新数据", httpMethod = "GET")
    @GetMapping("/sector/all")
    public Response<List<StockBlockDomain>> getSectorAll() {
        return stockService.getSectorLimit10();
    }

    //分页查询股票最新数据，并按照涨幅排序查询
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "分页查询股票最新数据，并按照涨幅排序查询", notes = "分页查询股票最新数据，并按照涨幅排序查询", httpMethod = "GET")
    @GetMapping("/stock/all")
    public Response<PageResponse> getStockPageInfo
    (
       @RequestParam(name = "page", defaultValue = "1",required = false) Integer page,
       @RequestParam(name = "pageSize", defaultValue = "20",required = false) Integer pageSize
    ) {
        return stockService.getStockPageInfo(page,pageSize);
    }

    //统计沪深两市个股最新交易数据，并按涨幅降序排序查询前4条数据
    @ApiOperation(value = "统计沪深两市个股最新交易数据，并按涨幅降序排序查询前4条数据", notes = "统计沪深两市个股最新交易数据，并按涨幅降序排序查询前4条数据", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public Response<List<StockUpdownDomain>> getStockIncrease() {
        return stockService.getStockIncrease();
    }

    //统计最新涨停跌停数据
    @ApiOperation(value = "统计最新涨停跌停数据", notes = "统计最新涨停跌停数据", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public Response<Map<String,List>> getStockUpDownCount() {
        return stockService.getStockUpDownCount();
    }

    //将指定页的股票数据导出到excel表下
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "将指定页的股票数据导出到excel表下", notes = "将指定页的股票数据导出到excel表下", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void getStockPageInfo
            (
                    @RequestParam(name = "page", defaultValue = "1",required = false) Integer page,
                    @RequestParam(name = "pageSize", defaultValue = "20",required = false) Integer pageSize,
                    HttpServletResponse response
            ) {
        stockService.stockExport(page,pageSize,response);
    }

    //统计国内A股大盘T日和T-1日成交量对比功能（成交量为沪市和深市成交量之和）
    @ApiOperation(value = "统计国内A股大盘T日和T-1日成交量对比功能（成交量为沪市和深市成交量之和）", notes = "统计国内A股大盘T日和T-1日成交量对比功能（成交量为沪市和深市成交量之和）", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public Response<Map<String,List>> getTradeAmtByInner() {
        return stockService.getTradeAmtByInner();
    }

    //统计当前时间下（精确到分钟），A股在各个涨跌区间股票的数量
    @ApiOperation(value = "统计当前时间下（精确到分钟），A股在各个涨跌区间股票的数量", notes = "统计当前时间下（精确到分钟），A股在各个涨跌区间股票的数量", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public Response<Map> getStockUpDown() {
        return stockService.getStockUpDown();
    }

    //查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "stockCode", value = "", required = true)
    })
    @ApiOperation(value = "查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据", notes = "查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据", httpMethod = "GET")
    @GetMapping("stock/screen/time-sharing")
    public Response<List<Stock4MinuteDomain>> stockScreenTimeSharing(@RequestParam(name = "code") String stockCode) {
        return stockService.stockScreenTimeSharing(stockCode);
    }

    //单个个股日K 数据查询 ，可以根据时间区间查询数日的K线数据
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "stockCode", value = "股票编码", required = true)
    })
    @ApiOperation(value = "单个个股日K 数据查询 ，可以根据时间区间查询数日的K线数据", notes = "单个个股日K 数据查询 ，可以根据时间区间查询数日的K线数据", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public Response<List<Stock4EvrDayDomain>> getDayKLinData(@RequestParam(name = "code") String stockCode) {
        return stockService.stockCreenDkLine(stockCode);
    }
}
